--跳空缺口
create or replace function getsttkqk(days int) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE '
	select b."date",b.code,b.macd, --(b.ma10-b.ma5)/b.ma5 , 
		s."name",s.industry from basic_data b  left join stocks s  on b.code=s.code 
	where 
	to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days||')
		and macd != ''NaN''
		and strpos(s."name",''ST'')=0
	  	and low > (select high from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code )
	  	and low <= (select min(low) from basic_data where to_date(date,''YYYY-MM-DD'') >= getwd(current_date,'||days-1||') and code=b.code )
	  	--and (select low from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,1) and code=b.code ) <=  (select min(low) from basic_data where to_date(date,''YYYY-MM-DD'') >= getwd(current_date,'||days-1||') and code=b.code )
		order by macd::float8
		;
' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';